/***********************************************************
 * Fulguro Example 1 : Alternate Sequential Filters
 ***********************************************************/


/*! 
 * \example example1.c <B>Alternate Sequential Filters</B>
 */

#include <flgrCoreTypes.h>
#include <flgrCoreErrors.h>
#include <flgrCoreData.h>
#include <flgrImageIO.h>
#include <flgrRtView.h>
#include <flgrMorphoBase.h>

int main(void) {
  FLGR_Data2D *imin;
  FLGR_Data2D *imout;
  FLGR_Data2D *imtmp;
  FLGR_Data2D *nhb;
  FLGR_RtView2D *scr0;
  int i;

  imin = flgr2d_load_pgm("../../images/gray/lena.pgm");
  imout = flgr2d_create_pixmap_from(imin);
  imtmp = flgr2d_create_pixmap_from(imin);
  

  scr0 = flgr2d_rtview_create(imin, 1, 2);

  flgr2d_rtview_refresh(scr0, imin, 0, 0);
  flgr2d_copy(imout,imin);

  for( i=1 ; i<100 ; i++) {
    nhb = flgr2d_create_neighborhood(i*2+1,i*2+1,imin->spp,imin->type,FLGR_RECT,FLGR_8_CONNEX);
    flgr2d_open(imtmp,imout,nhb);
    flgr2d_close(imout,imtmp,nhb);
    flgr2d_rtview_refresh(scr0, imout, 0, 1);
    flgr2d_destroy(nhb);
  }
  
  flgr2d_save_pgm(imout,"output.pgm",5);

  flgr2d_destroy(imin);
  flgr2d_destroy(imout);
  flgr2d_destroy(imtmp);
  flgr2d_rtview_destroy(scr0);

}


